{include file="public/header" /}
{load href="__PLUGINS__iCheck/icheck.min.js"}
{load href="__PLUGINS__iCheck/custom.css"}

<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <form class="form-horizontal" method="post">
            <div class="col-sm-12">
                <div class="tabs-container">

                    <div class="tab-content">
                        <div id="tab-1" class="tab-pane active">
                            <div class="ibox-content">

                                <div class="form-group">
                                    <label class="col-sm-2 control-label">性别：</label>
                                    <div class="col-sm-9">
                                        <div class="radio i-checks">
                                            <label>
                                                <input type="radio" value="0" name="sex" {present name="name"}{eq name="name.sex" value="0"}checked{/eq}{else /}checked{/present}>通用
                                            </label>
                                            <label>
                                                <input type="radio" value="1" name="sex" {present name="name"}{eq name="name.sex" value="1"}checked{/eq}{/present}>男
                                            </label>
                                            <label>
                                                <input type="radio" value="2" name="sex" {present name="name"}{eq name="name.sex" value="2"}checked{/eq}{/present}>女
                                            </label>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">内容：</label>
                                    <div class="col-sm-9">
                                        <textarea rows="10" id="text" placeholder="手动输入多个号码时使用英文分号分隔每个模板。" class="form-control" name="content">{present name="name"}{$name.content}{/present}</textarea>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">快速导入：</label>
                                    <div class="col-sm-9">
                                        <div class="btn btn-primary" onclick="txtload()">从txt导入</div>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
                            <input type="file" name="file" multiple="multiple" accept="text/plain" id="files" onchange="choosefile()" />
{include file="public/footer" /}

<script type="text/javascript">
    $(document).ready(function(){
        $(".i-checks").iCheck({
            checkboxClass: "icheckbox_square-green",
            radioClass: "iradio_square-green",
        })

    });
    function txtload() {
        document.getElementById('files').click();
    }
    function choosefile () {
        var fileList = document.getElementById('files').files;
        var nameStr = '';
        for (var i = 0; i < fileList.length; i++) {
            nameStr += `${i === 0 ? '' : ', '}${fileList[i].name}`;
            var reader = new FileReader();
            reader.readAsText(fileList[i], "UTF-8");
            reader.onload = function (e) {
                var content = e.target.result;
                console.log(content);
                const textAreaVal = document.getElementById('text').value;
                content=content.split(/[(\r\n)\r\n]+/).join('').split(';');
                txt = []
                content.forEach((item,index,array)=>{
                    item = item.trim().replace(/^，|，+$/g, '').replace(/^：|：+$/g, '');
                    if(item){
                        txt.push(item)
                    }
                })
                content = txt.join(';')
                if(content){
                    document.getElementById('text').value = (textAreaVal ? textAreaVal + ',' : '') + content;
                    layer.msg('本次导入 ' + txt.length + ' 个模板')
                }

            }
        }
    }
</script>
{include file="public/bottom" /}